/*
 * ON LOAD DA PAGINA
 */
$(document).ready(function()
{
	
	$('#nCdFormato').after('<a class="checkShipping" href="#">checar frete</a>');
	$('.checkShipping').live('click',function(){
		
		$('.loaderShipping').remove();
		$('.infoErrorShipping').remove();
		$('.checkShipping').after('<div class="loaderShipping loader">&nbsp;</div>');
		
		var url = 'http://' + location.hostname + '/correios/check-shipping/'
		var data = 'sCepDestino=05616060' + 
    	'&nCdFormato='+$('#nCdFormato').val()+
    	'&nVlPeso='+$('#nVlPeso').val()+
    	'&nVlAltura='+$('#nVlAltura').val()+ 
    	'&nVlComprimento='+$('#nVlComprimento').val()+ 
    	'&nVlLargura='+$('#nVlLargura').val()+
    	'&nVlDiametro='+$('#nVlDiametro').val();
    	 
		$.post(url, data, function(result)
		{
			$('.loaderShipping').remove();
			if( result.substr(0,2) != 'R$' )
			{
				$('.checkShipping').after('<div class="infoErrorShipping">'+result+'</div>');
			}
			else
			{
				$('.checkShipping').after('<div class="loaderShipping">'+result+'</div>');
			}
		});
		
		return false;
	})
});


